import com.alibaba.druid.pool.DruidDataSource;

import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {
        //创建druid数据源
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/test");
        dataSource.setUsername("root");
        dataSource.setPassword("coup");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setInitialSize(10);//最大连接数
        dataSource.setMaxActive(100);
        dataSource.setMinIdle(10);
        dataSource.setMaxWait(60000);
        dataSource.setValidationQuery("select 1");
        dataSource.setTestOnBorrow(true);
        dataSource.setTestOnReturn(true);
        dataSource.setPoolPreparedStatements(true);
        dataSource.setMaxPoolPreparedStatementPerConnectionSize(20);




       try{
        if (dataSource.getConnection()!=null){
            System.out.println("连接成功");
        }else {
            System.out.println("连接失败");
        }
        }catch (SQLException e){
           throw new RuntimeException(e);
       }
    }
}